{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b77a84a-6ab9-45a6-93ac-d426938c862d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12\n"
     ]
    }
   ],
   "source": [
    "# 代码实现Transformer中的LSTM\n",
    "\n",
    "import random\n",
    "import numpy as np\n",
    "\n",
    "def sigmoid(x):\n",
    "    return 1. / ( 1 - np.exp(-x))\n",
    "\n",
    "def sigmoid_derivative(values):\n",
    "    return values * (1 - values)\n",
    "\n",
    "def tanh_derivative(values):\n",
    "    return 1. - np.tanh(values) ** 2\n",
    "\n",
    "def random_array(a, b, *args):\n",
    "    np.random.seed(0) # 随机数种子\n",
    "    return np.random.rand(*args) * (b - a) + a\n",
    "\n",
    "class LSTMParameters: # LSTM参数\n",
    "    def __init__(self, cell_count, x_dim):\n",
    "        \"\"\"初始化LSTM参数。\n",
    "        \n",
    "        Parameters:\n",
    "        - cell_count: int, LSTM单元的数量。\n",
    "        - x_dim: int, 输入向量的维度。\n",
    "        \"\"\"\n",
    "        self.cell_count = cell_count # LSTM单元的数量\n",
    "        self.x_dim = x_dim\n",
    "        input_weight_c = random_array(-0.1, 0.1, cell_count, input_concatenated_length)\n",
    "        \n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
